import { Router } from 'express'
import {
  getArticles,
  getArticleById,
  createArticle,
  updateArticle,
  deleteArticle,
  getMyArticles,
  getComments,
  addComment,
  patchDefaultCovers
} from '../controllers/article.js'
import authMiddleware from '../middleware/auth.js'

const router = Router()

router.get('/', getArticles) // 获取文章列表
router.get('/my-articles', authMiddleware, getMyArticles) // 获取我的文章
router.post('/patch-default-covers', authMiddleware, patchDefaultCovers) // 更新默认封面
router.get('/:id', getArticleById) // 获取单篇文章
router.post('/', authMiddleware, createArticle) // 新增文章
router.put('/:id', authMiddleware, updateArticle) // 更新文章
router.delete('/:id', authMiddleware, deleteArticle) // 删除文章
router.get('/:id/comments', getComments) // 获取文章评论
router.post('/:id/comments', authMiddleware, addComment) // 添加评论

export default router
